package main

import (
	"fmt"
	"reflect"
)

/*
* Author: JacksonCoder
* CreateTime: 2025/5/20
 */
type Rect1 struct {
	Width  int
	Height int
	Name   string
}

// 通过统一的接口去实现属性设置
func SetRectAttr(r *Rect1, name string, value int) {
	var v = reflect.ValueOf(r)
	var field = v.Elem().FieldByName(name)
	field.SetInt(int64(value))
}

// 结构体也值值类型，也必须通过指针类型来修改
func main() {
	var r = Rect1{Width:590,Height: 3920}
	SetRectAttr(&r,"Width",100)
	SetRectAttr(&r,"Height",200)
	//SetRectAttr(&r,"Name","长方形")   不行
	fmt.Println(r)
}
